let instance;


/**
 * 统一的音效管理器
 */
export default class Music {
  bgMusic = tt.createInnerAudioContext();//背景音乐
  successMusic = tt.createInnerAudioContext();//点击成功声音
  failCikMusic = tt.createInnerAudioContext();//点击失败声音

  constructor() {
	this.isMusicOn = true; //背景音乐开启关闭
    if (instance) return instance;
    instance = this;
    this.bgMusic.loop = true; // 背景音乐循环播放
    this.bgMusic.autoplay = true; // 背景音乐自动播放
    this.bgMusic.src = 'https://xhy-1256039008.cos.ap-shanghai.myqcloud.com/xyx/img/bgm.mp3';// 背景音乐
    this.successMusic.src = 'https://xhy-1256039008.cos.ap-shanghai.myqcloud.com/xyx/img/eat.mp3';//点击成功声音
    this.failCikMusic.src = 'https://xhy-1256039008.cos.ap-shanghai.myqcloud.com/xyx/img/eat.mp3';//点击失败声音
  }
  //背景音乐切换
  toggleMusic() {
	  this.isMusicOn = !this.isMusicOn;
	  if(this.isMusicOn){
	  	this.playbgMusic()
	  }else{
	  	this.pauseShoot()
	  }
  }
	//背景音乐播放
  playbgMusic() {
    // this.bgMusic.currentTime = 0;
    this.bgMusic.play();
  }
	//背景音乐暂停
  pauseShoot() {
    this.bgMusic.pause();
  }	
  //点击成功声音播放
  playSuccessMusic() {
    this.successMusic.play();
  }
  	//点击成功音乐暂停
  pauseSuccessMusic() {
    this.successMusic.pause();
  }
  //点击失败声音播放
  playFailCikMusic() {
    this.failCikMusic.play();
  }
  	//点击失败音乐暂停
  pauseFailCikMusic() {
    this.failCikMusic.pause();
  }
}
